<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
${aier_doctype}
<html <s:property value="aier_html_xmlns" escape="false"/>>
<head>
<meta http-equiv="Content-Type" content="${aier_content_type}" />
<meta name="keywords" content="${aier_keyworks}" />
<meta name="description" content="${aier_description}" />
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}ui.css" />
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}text.css" />
<link rel="stylesheet"
	href="${aier_css_url}${aier_jqui_css}enhanced.css" />
<link rel="stylesheet" href="${aier_css_url}proxy/ag.css" />

<script type="text/javascript" src="${aier_js_url}j.js"></script>
<script type="text/javascript" src="${aier_js_url}b.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/hh/ui.js"></script>
<script type="text/javascript" src="${aier_js_url}97/WdatePicker.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/arrayList.js"></script>
<script type="text/javascript"
	src="${aier_js_url}${aier_jqui_js}custominput.js"></script>
<script type="text/javascript"
	src="${aier_js_url}${aier_jqui_js}text.js"></script>
</head>
<body>
	<div id="tabs">
		<ul>
			<li><a href="#tabs-1">考勤分类</a>
			</li>
		</ul>
		<div id="tabs-1" style="height: 500px;">
			<div class="d_content">
				<div class="d_scnOut" id="sel_gradeInfo"></div>
				<div class="d_scnOut">
					<div class="d_scname">
						<label for="txt_position">职务名</label>
					</div>
					<div class="d_sctext">
						<input type="text" id="txt_position" class="txt_scname">
					</div>
				</div>
				<div style="margin-left: 80px;">
					<table style="">
						<tr>
							<td><input type="checkbox" title="星期日" id=weekday1><label
								for="weekday1">星期日</label>
							</td>
							<td><input type="checkbox" title="星期一" id="weekday2"
								checked="checked"><label for="weekday2">星期一</label>
							</td>
							<td><input type="checkbox" title="星期二" id="weekday3"
								checked="checked"><label for="weekday3">星期二</label>
							</td>
							<td><input type="checkbox" title="星期三" id="weekday4"
								checked="checked"><label for="weekday4">星期三</label>
							</td>
							<td><input type="checkbox" title="星期四" id="weekday5"
								checked="checked"><label for="weekday5">星期四</label>
							</td>
							<td><input type="checkbox" title="星期五" id="weekday6"
								checked="checked"><label for="weekday6">星期五</label>
							</td>
							<td><input type="checkbox" title="星期六" id="weekday7"><label
								for="weekday7">星期六</label>
							</td>
							<td><input type="checkbox" title="不做考勤要求" id="box_noAd"><label
								id="txt_noAd" for="box_noAd">不做考勤要求</label></td>
						</tr>
					</table>
				</div>
				<div class="d_restTime">
					<div class="d_ampm">
						<span>上午</span>
					</div>
					<div class="d_startDate">
						<label>上班时间</label>
					</div>
					<div class="d_workDate">
						<input type="text" id="amStartTime"
							onfocus="WdatePicker({skin:'whyGreen',dateFmt:'HH:mm',maxDate:'#F{$dp.$D(\'amEndTime\')}',startDate:'08:00:00',readOnly:true})" />
					</div>
					<div class="d_endDate">
						<label>下班时间</label>
					</div>
					<div class="d_commutDate">
						<div>
							<input type="text" id="amEndTime"
								onfocus="WdatePicker({skin:'whyGreen',dateFmt:'HH:mm',minDate:'#F{$dp.$D(\'amStartTime\')}',startDate:'11:00:00',readOnly:true})" />
						</div>
					</div>
				</div>

				<div class="d_restTime">
					<div class="d_ampm">
						<span>下午</span>
					</div>
					<div class="d_startDate">
						<label>上班时间</label>
					</div>
					<div class="d_workDate">
						<input type="text" id="pmStartTime"
							onfocus="WdatePicker({skin:'whyGreen',dateFmt:'HH:mm',minDate:'#F{$dp.$D(\'amEndTime\')||$dp.$D(\'amStartTime\')}',startDate:'13:00:00'})" />
					</div>
					<div class="d_endDate">
						<label>下班时间</label>
					</div>
					<div class="d_commutDate">
						<input type="text" id="pmEndTime"
							onfocus="WdatePicker({skin:'whyGreen',dateFmt:'HH:mm',minDate:'#F{$dp.$D(\'amEndTime\')||$dp.$D(\'amStartTime\')||$dp.$D(\'pmStartTime\')}',startDate:'16:00:00'})" />
					</div>
				</div>
				<div id="d_agButs">
					<button onclick="SubSaved()"
						style="margin-left: 0px;margin-top: 0px;"
						class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
						role="button" aria-disabled="false">
						<span class="ui-button-text">添加职务</span>
					</button>
					<button id="b_agupdate" onclick="updateList()"
						style="margin-left: 110px;margin-top: -50px;visibility: hidden;"
						class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
						role="button" aria-disabled="false">
						<span class="ui-button-text">修改职务</span>
					</button>
				
				</div>
				<button id="but_previous"
					style="margin-left: 300px;margin-top: 0px;"
					class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
					role="button" aria-disabled="false">
					<span class="ui-button-text">上一步</span>
				</button>
				<button id="but_next" style="margin-left: 100px;margin-top: 0px;"
					class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
					role="button" aria-disabled="false">
					<span class="ui-button-text">下一步</span>
				</button>
			</div>
		</div>

	</div>
</body>
<script type="text/javascript">
	//存放数据的数组。
	var agdates = new ArrayList();

	//遍历数组
	function addSelect() {

		var temp = "<div class='d_scname'><label for='sel_position'>已有职务</label></div><div  class='sel_region'><select style='border-color:#45930b;' id='sel_position' onchange='selectList()'>";
		for ( var i = 0; i < agdates.size(); i++) {
			var list = agdates.get(i).split("/");
			temp += "<option value="+i+">" + list[0] + "</option>";

		}
		temp += "</select></div><button style='margin-top:-40px;margin-left:220px;' onclick='deleteList()' class='ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only' role='button' aria-disabled='false'><span class='ui-button-text'>删除分类</span></button>";
		$("#sel_gradeInfo").html(temp);
		$("#b_agupdate").css("visibility", "visible");

	}

	function selectList() {
		var list = agdates.get($("#sel_position").val());

		$('#txt_position').val(list.split("/")[0]);
		$('#amStartTime').val(list.split("/")[1]);
		$('#amEndTime').val(list.split("/")[2]);
		$('#pmStartTime').val(list.split("/")[3]);
		$('#pmEndTime').val(list.split("/")[4]);
		if ("w2222222" == list.split("/")[5]) {

			for ( var i = 1; i < 8; i++) {
				$('#weekday' + i).attr("checked", false);
			}

			$('#box_noAd').attr("checked", true);
		} else {
			$('#box_noAd').attr("checked", false);
		}

		if ("1" == list.split("/")[5].substring(1, 2)) {
			$('#weekday1').attr("checked", true);
		} else {
			$('#weekday1').attr("checked", false);
		}

		if ("1" == list.split("/")[5].substring(2, 3)) {
			$('#weekday2').attr("checked", true);
		} else {
			$('#weekday2').attr("checked", false);
		}

		if ("1" == list.split("/")[5].substring(3, 4)) {
			$('#weekday3').attr("checked", true);
		} else {
			$('#weekday3').attr("checked", false);
		}

		if ("1" == list.split("/")[5].substring(4, 5)) {
			$('#weekday4').attr("checked", true);
		} else {
			$('#weekday4').attr("checked", false);
		}

		if ("1" == list.split("/")[5].substring(5, 6)) {
			$('#weekday5').attr("checked", true);
		} else {
			$('#weekday5').attr("checked", false);
		}

		if ("1" == list.split("/")[5].substring(6, 7)) {
			$('#weekday6').attr("checked", true);
		} else {
			$('#weekday6').attr("checked", false);
		}

		if ("1" == list.split("/")[5].substring(7)) {
			$('#weekday7').attr("checked", true);
		} else {
			$('#weekday7').attr("checked", false);
		}

	}

	//创建数据
	function SubSaved() {
		//定义数组
		var dateList = new ArrayList();

		//定义数组中元素
		var gradeDate = "";

		if ($('#weekday1').attr("checked") == "checked") {
			dateList.add("1");
		} else {
			dateList.add("0");
		}
		if ($('#weekday2').attr("checked") == "checked") {
			dateList.add("1");
		} else {
			dateList.add("0");
		}
		if ($('#weekday3').attr("checked") == "checked") {
			dateList.add("1");
		} else {
			dateList.add("0");
		}
		if ($('#weekday4').attr("checked") == "checked") {
			dateList.add("1");
		} else {
			dateList.add("0");
		}
		if ($('#weekday5').attr("checked") == "checked") {
			dateList.add("1");
		} else {
			dateList.add("0");
		}
		if ($('#weekday6').attr("checked") == "checked") {
			dateList.add("1");
		} else {
			dateList.add("0");
		}
		if ($('#weekday7').attr("checked") == "checked") {
			dateList.add("1");
		} else {
			dateList.add("0");
		}
		if ($('#box_noAd').attr("checked") == "checked") {
			dateList.clear();
			dateList.add("2222222");
		}
		var alist = "w";
		for ( var i = 0; i < dateList.size(); i++) {
			var t = dateList.get(i);

			alist += t;
		}
		var agpos = $('#txt_position').val().trim();
		var agif = true;
		if (null == agpos || "" == agpos) {
			//agpos = " ";
			alert("请输入职务名称！");
		} else {
			if (!isnull(agdates) && 0 < agdates.size()) {
				for ( var i = 0; i < agdates.size(); i++) {
					var list = agdates.get(i).split("/");
					if (list[0] == agpos) {
						agif = false;
						alert("该职务分类已存在！请重新输入。");
					}
				}
			}
			if (agif) {
				gradeDate += agpos + "/" + $('#amStartTime').val() + "/"
						+ $('#amEndTime').val() + "/" + $('#pmStartTime').val()
						+ "/" + $('#pmEndTime').val() + "/" + alist;

				agdates.add(gradeDate);

				alert("添加成功");
			}

		}

		addSelect();
	}

	//修改数据
	function updateList() {
		//定义数组
		var dateList = new ArrayList();

		//定义数组中元素
		var gradeDate = "";

		if ($('#weekday1').attr("checked") == "checked") {
			dateList.add("1");
		} else {
			dateList.add("0");
		}
		if ($('#weekday2').attr("checked") == "checked") {
			dateList.add("1");
		} else {
			dateList.add("0");
		}
		if ($('#weekday3').attr("checked") == "checked") {
			dateList.add("1");
		} else {
			dateList.add("0");
		}
		if ($('#weekday4').attr("checked") == "checked") {
			dateList.add("1");
		} else {
			dateList.add("0");
		}
		if ($('#weekday5').attr("checked") == "checked") {
			dateList.add("1");
		} else {
			dateList.add("0");
		}
		if ($('#weekday6').attr("checked") == "checked") {
			dateList.add("1");
		} else {
			dateList.add("0");
		}
		if ($('#weekday7').attr("checked") == "checked") {
			dateList.add("1");
		} else {
			dateList.add("0");
		}
		if ($('#box_noAd').attr("checked") == "checked") {
			dateList.clear();
			dateList.add("2222222");
		}

		var alist = "w";

		for ( var i = 0; i < dateList.size(); i++) {
			var t = dateList.get(i);

			alist += t;
		}

		agdates.remove($("#sel_position").val());
		gradeDate += $('#txt_position').val() + "/" + $('#amStartTime').val()
				+ "/" + $('#amEndTime').val() + "/" + $('#pmStartTime').val()
				+ "/" + $('#pmEndTime').val() + "/" + alist;
		agdates.add(gradeDate);

		alert("修改成功");
		addSelect();

	}

	//删除数据
	function deleteList() {

		agdates.remove($("#sel_position").val());
		alert("删除成功");
		addSelect();

	}

	$("#tabs").tabs();
	$('#but_previous').click(function() {
		location.href = "${aier_url}proxy/creates_createInfo${aier_suffix}";
	});

	//转跳之前将数据储存到session中
	$('#but_next')
			.click(
					function() {
						var fun = function(data) {
							if (data.s == 10001) {
								location.href = "${aier_url}proxy/creates_classesManage${aier_suffix}?pid=${pid}";
							}

						};

						var aglist = "";
						for ( var i = 0; i < agdates.size(); i++) {
							var t = agdates.get(i);

							aglist += t + ",";
						}
						exeAjax(
								ajaxUrl("${aier_url}${aier_urijs}quicksc_card_addlist${aier_suffix}"),
								fun, {
									"agdates" : aglist,
								});
					});

	//进入页面的时候加载数据
	function loadAgInfo() {
		var fun = function(data) {
			if (10001 == data.s) {
				agdates.clear();
				for ( var i = 0; i < data.agdates.split(",").length; i++) {
					var li = data.agdates.split(",")[i];
					if (!isnull(li)) {
						agdates.add(li);
					}
				}
				addSelect();
				selectList();
			}

		};

		var aglist = "";
		for ( var i = 0; i < agdates.size(); i++) {
			var t = agdates.get(i);

			aglist += t + ",";
		}
		exeAjax(
				ajaxUrl("${aier_url}${aier_urijs}quicksc_card_selectlist${aier_suffix}"),
				fun, {
					"agdates" : aglist,
				});
	}

	loadAgInfo();
</script>
</html>